// pages/killPrice/killPrice.js
var utils = require('../../utils/util.js');
Page({
  /**
   * 页面的初始数据
   */
  data: {
	  banner: '/images/banner3.jpg',
    currentPage: 1
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this;
    that.setData({
      number: wx.getStorageSync("number")
    })
    that.goodslist(that.data.currentPage);
  },
  onShow: function(e) {
    var that = this;

  },
  //所有的商品列表
  goodslist: function(currentPage) {
    var that = this;
    utils.showLoading();
    utils.http("/api/v1/bargaingoods/goods_list", {
      page: currentPage
    }, function(res) {
      utils.hideLoading();
      console.log(res.datas);
      var allpost = that.data.allListData;
      if (allpost == undefined) {
        allpost = [];
      }
      for (var i in res.datas) {
        res.datas[i].number = 0;
        allpost.push(res.datas[i])
      }
      if (res.datas.length < 10) {
        that.setData({
          tishi_title: '已加载全部',
        });
      } else {
        that.setData({
          tishi_title: '加载更多',
        });
      }
      that.setData({
        allListData: allpost,
        ready: res.datas.length == 0 ? 1 : 2,
      })

    })
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    var that = this;
    if (that.data.ready == 2) {
      var page = that.data.currentPage + 1
      that.setData({
        currentPage: page,
      })
      that.goodslist(page)
    }
  },
  //商品详情
  noFrutisDetailsTap: function(e) {
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/killPrice/details?id=' + id,
    })
  },
  onShareAppMessage: function() {
    return utils.share();
  }
})